Install Packages

install.packages(c("ggplot2", "plotly", "DT", "leaflet", "readxl"))

Load Libraries

library(ggplot2)
library(plotly)
library(DT)
library(leaflet)
library(readxl)

Load Data

data <- read_excel("FoodAccessResearchAtlasData2019.xlsx")
data <- data.frame(
  County = c("Fulton", "DeKalb", "Clayton", "Gwinnett", "Cobb", 
             "Chatham", "Richmond", "Bibb", "Dougherty", "Hancock", 
             "Fayette", "Terrell", "Randolph", "Calhoun", "Henry", 
             "Douglas", "Muscogee"),

  Food_Insecurity_Rate = c(18.2, 16.5, 19.3, 12.7, 10.5, 
                           20.1, 17.4, 19.8, 21.3, 22.5, 
                           15.6, 23.1, 24.7, 16.9, 14.8, 
                           18.9, 19.2),

  Supermarket_Distance = c(2.1, 1.8, 2.4, 1.5, 1.3, 
                           2.7, 3.1, 2.9, 3.5, 3.8, 
                           1.9, 4.2, 4.5, 2.3, 1.6, 
                           2.8, 3.0),

  Vehicle_Access = c(78, 85, 72, 90, 88, 
                     70, 65, 68, 60, 55, 
                     82, 58, 54, 80, 86, 
                     75, 73),

  Latitude = c(33.749, 33.774, 33.557, 34.002, 33.899, 
               32.083, 33.470, 32.806, 31.578, 33.287, 
               33.448, 31.777, 31.777, 31.525, 33.451, 
               33.751, 32.464),

  Longitude = c(-84.388, -84.296, -84.353, -84.033, -84.564, 
                -81.099, -81.987, -83.697, -84.176, -82.997, 
                -84.454, -84.440, -84.803, -84.524, -84.155, 
                -84.660, -84.992)
)

Interactive Scatter Plot

fig <- plot_ly(
  data,
  x = ~Supermarket_Distance,
  y = ~Food_Insecurity_Rate,
  text = ~County,
  type = "scatter",
  mode = "markers",
  marker = list(size = 10, color = ~Vehicle_Access, colorscale = "Viridis"),
  hoverinfo = "text+x+y"
) %>%
  layout(
    title = "Food Insecurity vs. Supermarket Distance in Georgia",
    xaxis = list(title = "Supermarket Distance (miles)"),
    yaxis = list(title = "Food Insecurity Rate (%)")
  )

fig

Interactive Map

m <- leaflet(data) %>% 
  addTiles() %>% 
  addCircleMarkers(
    lat = ~Latitude, 
    lng = ~Longitude, 
    radius = ~Food_Insecurity_Rate / 2,
    color = ifelse(data$Food_Insecurity_Rate < 15, "purple", "orange"),
    popup = ~paste(County, "-", Food_Insecurity_Rate, "% food insecurity,", Supermarket_Distance, "miles to supermarket")
  )

m

Interactive Table

datatable(data, options = list(pageLength = 5, autoWidth = TRUE))